home *** CD-ROM | disk | FTP | other *** search
- Path: news.halcyon.com!usenet
- From: normanb@halcyon.com (Norm Bryar)
- Newsgroups: comp.lang.c++
- Subject: Re: Calling virtual functions
- Date: Mon, 19 Feb 1996 19:03:10 GMT
- Organization: Northwest Nexus Inc.
- Message-ID: <4gahgc$9o3@news.halcyon.com>
- References: <wbayever.1.000F69F7@ucla.edu>
- NNTP-Posting-Host: blv-pm12-ip19.halcyon.com
- X-Newsreader: Forte Free Agent 1.0.82
-
- I believe the compiler (linker, really) should have errored. MSVC4
- would have.
- Try giving the RootFinder::FindRoot pure virtual a body, which
- is not only legal but usually necessary for just such scenarios as the
- one you describe.
-
- class RootFinder {
- virtual BOOL FindRoot(complex &root) = 0
- { return FALSE; }
-
- I've done this for normal classes, but haven't thrown in templates on
- top of the works. Let me know if this does it for you.
-
- --Norm
-
-
- wbayever@ucla.edu (Wayne Bayever) wrote:
-
- >I have the following two class templates:
-
- >/***************************************************************************
- > * Class: RootFinder *
- > * Purpose: Superclass for all rootfinding methods *
- > ***************************************************************************/
-
- >template <class T>
- >class RootFinder {
- > .
- > .
- > .
- > public:
- > virtual BOOL FindAllRoots(); // Calls FindRoot(complex &) several times
- > virtual BOOL FindRoot(complex &root) = 0;
- >};
-
- >/***************************************************************************
- > * Class: MullerRootFinder *
- > * Purpose: Implementation of Muller's root finding method *
- > ***************************************************************************/
-
- >template <class T>
- >class MullerRootFinder : public virtual RootFinder<T> {
- > public:
- > BOOL FindRoot(complex &root);
- >};
-
- >The function FindAllRoots() in RootFinder calls FindRoot(complex &) several
- >times.
- >I am using Borland C++ 3.1 to compile my program, and no errors show up. But
- >when I run the program I get an error:
- >Pure virtual function called
-
- >My main() looks like this:
- >void main() {
- > .
- > .
- > .
- > MullerRootFinder<double> mrf(14);
- > .
- > .
- > .
- > mrf.FindAllRoots(); <<<<<<<< This is the line which produces the error
-
- >}
-
- >Can you not call a pure virtual function from a base class function if you
- >only define it in a subclass?
- >I am going to derive several other root finding classes from RootFinder, I
- >hope that I can do it without copying FindAllRoots() in each class.
-
- >Please let me know if I am doing something wrong,
-
- >Wayne Bayever
-
-
-